<html>
    <head>
        <title>Test</title>
        <style></style>
        <script type="module">

import { h, render, Component } from 'preact';

JSX = h;   // let's use PReact::h() as a driver of JSX expressions

class Clock extends Component {

    state = { time: Date.now() };

    componentDidMount() {
        // update time every second
        this.timer = setInterval(() => {
            this.setState({ time: Date.now() });
        }, 1000);
    }

    componentWillUnmount() {
        // stop when not renderable
        clearInterval(this.timer);
    }

    render(props, state) {
        let time = new Date(state.time).toLocaleTimeString();
        return <h2>PReact's time:<span>{ time }</span></h2>;
    }
}

// render an instance of Clock into <body>:
render(<Clock />, document.body);

        </script>
    </head>
    <body>
    </body>
</html>